import axios from "axios";
import {ElMessage} from "element-plus";

const server =axios.create({
    baseURL:'http://localhost:8080',
    timeout:600000
})

server.interceptors.request.use(config=>{
    console.log('axios请求拦截器执行了')
    let token = sessionStorage.getItem("token")
    config.headers["token"] = token
    return config
},error=>{
    console.log(error)
    return Promise.reject(error)
})

server.interceptors.response.use(resp=>{
        // console.log(resp)
        if (resp.data.code === 1004) {
            ElMessage.error(resp.data.msg+"请先登录")
            sessionStorage.removeItem("token")
            window.location.href = '/login'
        }
        return resp;
    }
    ,error=>{
        console.log(error)
        return Promise.reject(error)})

export default server